import 'package:C20Driver/provider/driver_information.dart';
import 'package:C20Driver/service/request.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

class PersonalDetailData extends StatefulWidget {
  @override
  _PersonalDetailDataState createState() => _PersonalDetailDataState();
}

class _PersonalDetailDataState extends State<PersonalDetailData> {
  List imageURLs = [
    'http://img.a.huashichuxing.com/headIcon/head_icon/head.png',
    'http://img.a.huashichuxing.com/headIcon/head_icon/tuzi.png',
    'http://img.a.huashichuxing.com/headIcon/head_icon/ji.png',
    'http://img.a.huashichuxing.com/headIcon/head_icon/niu.png',
    'http://img.a.huashichuxing.com/headIcon/head_icon/laohu.png',
    'http://img.a.huashichuxing.com/headIcon/head_icon/houzi.png',
  ];
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    DriverInformation provider =
        Provider.of<DriverInformation>(context, listen: false);
    return Scaffold(
      appBar: AppBar(
        title: Text('我的信息'),
        elevation: 0,
      ),
      body: Container(
        padding: EdgeInsets.all(
          ScreenUtil().setWidth(32),
        ),
        width: double.infinity,
        height: double.infinity,
        color: Color(0xffffffff),
        child: Column(
          children: [
            Container(
              decoration: BoxDecoration(
                border: Border(
                  bottom: BorderSide(
                    width: ScreenUtil().setWidth(1),
                    color: Color(0xffeeeeee),
                  ),
                ),
              ),
              height: ScreenUtil().setWidth(130),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '头像',
                    style: TextStyle(
                        color: Color(0xff333333),
                        fontSize: ScreenUtil().setWidth(30),
                        fontWeight: FontWeight.w400),
                  ),
                  InkWell(
                    onTap: () {
                      _selectHeadImage(context);
                    },
                    child: Row(
                      children: [
                        Consumer<DriverInformation>(
                            builder: (context, state, chile) {
                          return Image.network(
                            state.driverInfo.headimgurl,
                            width: ScreenUtil().setWidth(120),
                            height: ScreenUtil().setWidth(120),
                          );
                        }),
                        SizedBox(
                          width: ScreenUtil().setWidth(5),
                        ),
                        Icon(
                          Icons.chevron_right,
                          color: Color(0xff999999),
                        ),
                      ],
                    ),
                  )
                ],
              ),
            ),
            Container(
              decoration: BoxDecoration(
                border: Border(
                  bottom: BorderSide(
                    width: ScreenUtil().setWidth(1),
                    color: Color(0xffeeeeee),
                  ),
                ),
              ),
              height: ScreenUtil().setWidth(130),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '昵称',
                    style: TextStyle(
                        color: Color(0xff333333),
                        fontSize: ScreenUtil().setWidth(30),
                        fontWeight: FontWeight.w400),
                  ),
                  Text(
                    '${provider.driverInfo.driverName}',
                    style: TextStyle(
                        color: Color(0xff333333),
                        fontSize: ScreenUtil().setWidth(32),
                        fontWeight: FontWeight.w400),
                  ),
                ],
              ),
            ),
            Container(
              decoration: BoxDecoration(
                border: Border(
                  bottom: BorderSide(
                    width: ScreenUtil().setWidth(1),
                    color: Color(0xffeeeeee),
                  ),
                ),
              ),
              height: ScreenUtil().setWidth(130),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '电话',
                    style: TextStyle(
                        color: Color(0xff333333),
                        fontSize: ScreenUtil().setWidth(30),
                        fontWeight: FontWeight.w400),
                  ),
                  Text(
                    '${provider.driverInfo.driverPhone}',
                    style: TextStyle(
                        color: Color(0xff333333),
                        fontSize: ScreenUtil().setWidth(32),
                        fontWeight: FontWeight.w400),
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  /// 修改座位数
  void _selectHeadImage(context) async {
    final option = await showModalBottomSheet(
        context: context,
        backgroundColor: Colors.transparent,
        builder: (BuildContext context) {
          return Container(
            padding: EdgeInsets.all(
              ScreenUtil().setWidth(32),
            ),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(
                  ScreenUtil().setWidth(32),
                ),
                topRight: Radius.circular(
                  ScreenUtil().setWidth(32),
                ),
              ),
            ),
            height: ScreenUtil().setWidth(550.0),
            child: Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    SizedBox(
                      width: ScreenUtil().setWidth(10),
                    ),
                    Text(
                      '请选择头像',
                      style: TextStyle(
                          color: Color(0xff333333),
                          fontSize: ScreenUtil().setWidth(30),
                          fontWeight: FontWeight.w500),
                    ),
                    InkWell(
                      onTap: () {
                        Navigator.pop(context);
                      },
                      child: Icon(
                        Icons.close,
                        color: Color(0xff999999),
                        size: ScreenUtil().setWidth(40),
                      ),
                    ),
                  ],
                ),
                SizedBox(
                  height: ScreenUtil().setWidth(40),
                ),
                Divider(
                  color: Color(0xffeeeeee),
                  height: ScreenUtil().setWidth(1),
                ),
                SizedBox(
                  height: ScreenUtil().setWidth(60),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    InkWell(
                      onTap: () {
                        Navigator.pop(context, 0);
                      },
                      child: Image.asset(
                        'assets/icon/headimg1.png',
                        width: ScreenUtil().setWidth(136),
                        height: ScreenUtil().setWidth(136),
                      ),
                    ),
                    InkWell(
                      onTap: () {
                        Navigator.pop(context, 1);
                      },
                      child: Image.asset(
                        'assets/icon/headimg2.png',
                        width: ScreenUtil().setWidth(136),
                        height: ScreenUtil().setWidth(136),
                      ),
                    ),
                    InkWell(
                      onTap: () {
                        Navigator.pop(context, 2);
                      },
                      child: Image.asset(
                        'assets/icon/headimg3.png',
                        width: ScreenUtil().setWidth(136),
                        height: ScreenUtil().setWidth(136),
                      ),
                    ),
                  ],
                ),
                SizedBox(
                  height: ScreenUtil().setWidth(40),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    InkWell(
                      onTap: () {
                        Navigator.pop(context, 3);
                      },
                      child: Image.asset(
                        'assets/icon/headimg4.png',
                        width: ScreenUtil().setWidth(136),
                        height: ScreenUtil().setWidth(136),
                      ),
                    ),
                    InkWell(
                      onTap: () {
                        Navigator.pop(context, 4);
                      },
                      child: Image.asset(
                        'assets/icon/headimg5.png',
                        width: ScreenUtil().setWidth(136),
                        height: ScreenUtil().setWidth(136),
                      ),
                    ),
                    InkWell(
                      onTap: () {
                        Navigator.pop(context, 5);
                      },
                      child: Image.asset(
                        'assets/icon/headimg6.png',
                        width: ScreenUtil().setWidth(136),
                        height: ScreenUtil().setWidth(136),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          );
        });
    if (option != null) {
      String headUrl = imageURLs[option];
      print(headUrl);
      Request.modifyHeadImg(headUrl).then((value) {
        Request.getSetDriverInfo(context);
      });
    }
  }
}
